﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace YDT_SeckillService.Migrations
{
    /// <inheritdoc />
    public partial class seckillservice : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "Seckills",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    TimeTitleUrl = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SeckillDate = table.Column<DateOnly>(type: "date", nullable: false),
                    SeckillStartTime = table.Column<TimeOnly>(type: "time", nullable: false),
                    SeckillEndTime = table.Column<TimeOnly>(type: "time", nullable: false),
                    TimeStatus = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Seckills", x => x.Id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "SeckillProducts",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    SeckillType = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SeckillName = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SeckillUrl = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SeckillPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    SeckillStock = table.Column<int>(type: "int", nullable: false),
                    SeckillPercent = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TimeId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    ProductId = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
                    SeckillLimit = table.Column<int>(type: "int", nullable: false),
                    SeckillDescription = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SeckillIsTop = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    SeckillStatus = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    OriginalStock = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "datetime(6)", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SeckillProducts", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SeckillProducts_Seckills_TimeId",
                        column: x => x.TimeId,
                        principalTable: "Seckills",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_SeckillProducts_ProductId",
                table: "SeckillProducts",
                column: "ProductId");

            migrationBuilder.CreateIndex(
                name: "IX_SeckillProducts_SeckillIsTop",
                table: "SeckillProducts",
                column: "SeckillIsTop");

            migrationBuilder.CreateIndex(
                name: "IX_SeckillProducts_SeckillStatus",
                table: "SeckillProducts",
                column: "SeckillStatus");

            migrationBuilder.CreateIndex(
                name: "IX_SeckillProducts_TimeId",
                table: "SeckillProducts",
                column: "TimeId");

            migrationBuilder.CreateIndex(
                name: "IX_Seckills_SeckillDate",
                table: "Seckills",
                column: "SeckillDate");

            migrationBuilder.CreateIndex(
                name: "IX_Seckills_TimeStatus",
                table: "Seckills",
                column: "TimeStatus");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "SeckillProducts");

            migrationBuilder.DropTable(
                name: "Seckills");
        }
    }
}
